﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Web.Http;
using Domain.Interface;
using Domain.Model;
using Newtonsoft.Json;
using WebAPI.Attributes;

namespace WebAPI.Controllers
{
    [RoutePrefix("api/Login")]
    public class LoginController : ApiController
    {
        public IClass1 _Class1 { set; get; }
        /// <summary>
        /// 登录接口
        /// </summary>
        public ILoginInfo _Login { set; get; }
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        [HttpGet, HttpPost, Route("Signin")]
        public bool Signin(string username, string password)
        {
            return _Login.Signin(username, System.Web.HttpUtility.UrlDecode(password, System.Text.Encoding.UTF8));
        }
        [HttpPost]
        [Route("Test")]
        public string Test([FromBody]dynamic str)
        {
            //var result = JsonConvert.DeserializeObject<dynamic>(str);
            return JsonConvert.SerializeObject(str);
            //return str.ToString();
        }
        [HttpGet]
        [RunningLogAspect(MethodName = "测试2")]
        [WriteFileExceptionAspect]
        public void Test2()
        {
            _Class1.Add();
        }
        [HttpGet, RunningLogAspect(MethodName = "获取权限树"), Route("GetMyPowerTree"), WriteFileExceptionAspect]
        public List<Domain_PowerTree> GetMyPowerTree([FromUri]string username)
        {
            string treestr = _Login.GetUserPower(username);
            return JsonConvert.DeserializeObject<List<Domain_PowerTree>>(treestr);
        }
    }
}
